<html>
<head>
    <meta charset="UTF-8">
    <title>权限列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
</head>
<body>
<div class="demoTable" style="text-align: center">
    <div class="layui-inline">
        <input class="layui-input" name="apuser" id="apuser" placeholder="编号" autocomplete="off">
    </div>
    <div class="layui-inline">
        <input class="layui-input" name="aname" id="aname" placeholder="姓名" autocomplete="off">
    </div>
    <div class="layui-inline">
        <input class="layui-input" name="aphone" id="aphone" placeholder="手机号" autocomplete="off">
    </div>
    <button class="layui-btn" id="searchBtn" data-type="reload">搜索</button>
</div>
<table class="layui-hide" id="demo" lay-filter="test"></table>
<script type="text/jsp" id = "barDemo">
     <a class="layui-btn layui-btn-xs" lay-event="pession">权限设置</a>
</script>
<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/layui/layui.js"></script>
<script>
    layui.use(['table','layer','jquery'], function(){
        var table = layui.table;
        var  layer = layui.layer;
        var  $ = layui.jquery;
        var form = layui.form;
        //第一个实例
        table.render({
            elem: '#demo'
            ,height: document.body.clientHeight-180
            ,url: '/RoleController/selectAll1' //数据接口
            ,page:true
            ,id:'testReload'
            ,cols: [[ //表头
                 {field: 'rid', title: 'ID', width:80, sort: true}
                ,{field: 'user', title: '用户编号', width:180, sort: true,
                    templet: function (d) {
                        return d.user.apuser;
                    }}
                ,{field: 'roleType', title: '角色', width:100, sort: true}
                ,{field: 'user', title: '姓名', width:180, sort: true,
                    templet: function (d) {
                        return d.user.aname;
                    }}
                ,{field: 'user', title: '手机号', width:180, sort: true,
                        templet: function (d) {
                            return d.user.aphone;
                        }}
                ,{field: 'right', title: '操作', width: 180, toolbar:'#barDemo'}
            ]]
            ,toolbar:'#toolbar',//表格头信息
            parseData: function (rs) {//数据格式解析
                console.log(rs);
                if (rs.code == 200) {
                    return {
                        "code": rs.code,
                        "msg": rs.msg,
                        "count": rs.date.total,
                        "data": rs.date.list
                    }
                }
            },
            response: {	// 设置响应码
                statusCode: 200 //规定成功的状态码，默认：0
            }
        });
        //监听行事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            console.log(data.rid)
            if (obj.event === 'pession') {
                open("详情页面", "/view/power/authority.html?rid=" + data.rid);
            }
        });
        //"用户添加页面",
        function open(title,url){
            layer.open({
                type: 2
                ,title: title
                ,content:url
                ,offset: '50px'
                ,area: ['500px', '60%']
                ,end:function () {
                    table.reload('testReload');
                }
            });
        }

        function searchBtn(){

        }

        var $ = layui.$, active = {
            reload: function () {
                var apuser = $('#apuser');
                var aname = $('#aname');
                var aposition = $('#aposition');
                var aphone = $('#aphone');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        "apuser": apuser.val(),
                        "aposition": aposition.val(),
                        "aname": aname.val(),
                        "aphone": aphone.val()
                    }
                });
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>